package usbcali.edu.co.pqrs.dataaccess.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import usbcali.edu.co.pqrs.dataaccess.api.HibernateDaoImpl;
import usbcali.edu.co.pqrs.modelo.ParametrosPqr;
import usbcali.edu.co.pqrs.modelo.dto.ParametrosPqrDTO;

/**
 * A data access object (DAO) providing persistence and search support for
 * ParametrosPqr entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see lidis.ParametrosPqr
 */
@Scope("singleton")
@Repository("ParametrosPqrDAO")
public class ParametrosPqrDAO extends HibernateDaoImpl<ParametrosPqr, Long>
		implements IParametrosPqrDAO {
	private static final Logger log = LoggerFactory
			.getLogger(ParametrosPqrDAO.class);
	@Resource
	private SessionFactory sessionFactory;

	public static IParametrosPqrDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (IParametrosPqrDAO) ctx.getBean("ParametrosPqrDAO");
	}

	@Override
	public List<ParametrosPqrDTO> traerParametroConNombre(String nombre) {
		  List<ParametrosPqrDTO> list = null;
		  
		  try {
		   
		   Query query = getSession().getNamedQuery("traer_parametro");
		   query.setParameter("pDescripcionParam", nombre);
		   query.setResultTransformer(Transformers.aliasToBean(ParametrosPqrDTO.class));
		   list = query.list();
		   
		  } catch (Exception e) {
		    e.printStackTrace();
		  }
		  
		  return list;
	}
}
